<button class="layui-btn layui-btn-sm" onclick="singleAdd()">
	<i class="layui-icon layui-icon-add-1"></i> ${button.name!'新增'}
</button>
<script type="text/javascript">
    var singleAdd = function () {
    	var code = '${object.code}';
    	
    	var node = singletree.selectNode;

		// 默认新增到根下
		var parentId = singletree.rootValue;
		// 如果选中节点,则使用选中节点
		if (node) {
			parentId = node[singletree.idField];
		}
		
    	var ref = "?ref=" + singletree.parentField + ":" + parentId;
        var url = $.str.format('/form/add/{0}{1}', code, ref);

    	if(parentId == 0){
    		layer.confirm('也可主动选择一个父节点进行添加', {
				title : '未选择父节点,确认添加到根节点下?',
				icon : 3,
				btn : [ '确定', '取消' ]
			}, function(i) {
				addNode(url);
				layer.close(i);
			});
			return;
		}
    	
    	addNode(url);
    }
    
    function addNode(url){
    	var width = ${menu.config.params.width!'720'};
    	var height = ${menu.config.params.height!'undefined'};
    	
    	dialog(function(){
    		location.reload();
    	}, '${I18N(button.name)} ${object.name}', url , width, height);
	}
</script>